package leetcode;

public class MinimumPartition {
    public static void main(String[] args) {
        MinimumPartition minimumPartition = new MinimumPartition();
        System.out.println(minimumPartition.minimumPartition("1", 1));
    }

    public int minimumPartition(String s, int k) {
        int ans = 0;
        char[] chars = s.toCharArray();
        int i = 0;
        while (i < s.length()) {
            if (chars[i] - '0' > k) {
                return -1;
            } else if (chars[i] - '0' == k) {
                ans++;
                i++;
            } else {
                StringBuilder sb = new StringBuilder();
                int j = i;
                long value;
                for (; j < s.length(); j++) {
                    sb.append(chars[j]);
                    value = Long.parseLong(sb.toString());
                    if (value > k) {
                        i = j;
                        break;
                    } else if (value == k) {
                        i = j + 1;
                        break;
                    } else {
                        i++;
                    }
                }
                ans++;
            }
        }
        return ans;
    }
}
